package com.keliangliu.demo.beanPostProcessor;

import com.keliangliu.demo.bean.BeanDemo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Component
public class MyBeanProcessor implements BeanPostProcessor, ApplicationContextAware, InitializingBean {



    public MyBeanProcessor() {
        System.out.println("MyBeanProcessor 无参构造方法执行");
    }
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof BeanDemo) {
            Class clazz = bean.getClass();
            System.out.println(clazz.getAnnotations().length);
            System.out.println(clazz.getAnnotatedSuperclass());
        }
        return bean;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("实现了aware");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("MyBeanProcessor afterPropertiesSet实现");
    }
}
